package com.hjj.web.service.impl;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hjj.web.entity.User;
import com.hjj.web.mapper.UserMapper;
import com.hjj.web.service.IUserService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hejiajun
 * @since 2020-12-04
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    /**
     * 根据用户名 查询对应的 User
     *
     * @param userName 用户名
     * @return
     */
    @Override
    public User getUserByName(String userName) {
        // 根据 用户名查询
        User user = baseMapper.selectOne(Wrappers.lambdaQuery(new User())
                .eq(User::getUserName, userName));
        return user;
    }

    /**
     * 根据 用户id 查询用户名
     *
     * @param userId
     * @return
     */
    @Override
    public String getNameById(Long userId) {
        User user = baseMapper.selectById(userId);
        return user.getUserName();
    }
}
